﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/SystemManagement/Views/Shared/LigerUI.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">



    <title>UserIndex</title>

    <script type="text/javascript">
        var grid = null;

        $(function () {
            f_showGrid('');

            $("#toptoolbar").ligerToolBar({ items: [
                { text: '增加', click: f_add, icon: 'add' },
                { line: true },
                { text: '修改', click: f_modify, icon: 'modify' },
                { line: true },
                { text: '删除', click: f_delete, icon: 'delete' },
                { line: true },
                { text: '用户角色', click: f_role }
            ]
            });

            //隐藏Grid的行
            //hideColumn();
        });


        function f_add() {
            //hideColumn();

            w = f_openWindow('/SystemManagement/User/UserAdd', '添加用户', 500, 400);
        }



        function f_delete() {

            var row = grid.getSelectedRow();

            if (row) {

                $.ligerDialog.confirm('确定要删除选中的记录吗？', function (yes) {
                    if (yes) {
                        w = $.get('/SystemManagement/User/DeleteUser', { userId: row.userid }, function (data) {
                            $.ligerDialog.success(data, function () {
                                f_reload();
                            });

                        });
                    }
                })

            } else {
                $.ligerDialog.warn('请选择要删除的记录！')

            }
        }

        function f_modify() {

            var row = grid.getSelectedRow();

            if (row) {
                w = f_openWindow('/SystemManagement/User/UserEdit/' + row.userid, '修改用户信息', 500, 400);
            } else {
                $.ligerDialog.warn('请选择要修改的记录！')

            }


            //$.ligerWindow.show({ width: 500, height: 400, left: 100, top: 50, title: '修改用户信息', url: url });

        }


        function f_search() {

            grid.options.url = encodeURI('<%=Url.Action("GetUser","User")%>' + '/?conditions=' + $.trim($("#txtCondtions").val()));
            f_reload();
            //f_showGrid($.trim($("#txtCondtions").val()));
        }

        function f_role()
        {
            var row = grid.getSelectedRow();

            if (row) {
                w = f_openWindow('/SystemManagement/User/UserRole/' + row.userid, '用户角色', 500, 400);
            } else {
                $.ligerDialog.warn('请先选择一个用户！')

            }

        }

        //隐藏Grid的行
        function hideColumn()
        {
            alert("a");
            $(".l-grid-hd-cell[columnindex='0']", grid.gridheader).hide();
            $(".l-grid-row-cell[columnindex='0']", grid.gridbody).hide();
        }

        function getCheckedData()
        {
            var rows = grid.getCheckedRows();
            var str = "";
            $(rows).each(function ()
            {
                str += this.user_id + ",";
            });
            $.ligerDialog.alert('选择的是' + str);
        }
        function f_openWindow(url, title, width, height)
        {
            //return $.ligerWindow.show({ width: width, height: height, left: 200, top: 20, title: title, url: url });
            return $.ligerDialog.open({ url: url, width: width, height: height, title: title, modal: true });
        }

        var w;

        function f_close(result)
        {

            $.ligerDialog.success("保存成功！");
            w.close();
            
        }


        function f_reload()
        {
            //var manager = $("#maingrid")[0].manager;
            grid.loadData(true);
        }

        function f_showGrid(conditions)
        {
           
            grid = $("#maingrid").ligerGrid({
                columns: [{ display: '主键', name: 'userid', isAllowHide: false, hide: 1, width: 40 },
                    { display: '用户名', name: 'userName' }, { display: '密码', name: 'password', isSort: true },
                    { display: '姓名', name: 'name' }, { display: '性别', name: 'gender', width: 40 },
                    { display: '生日', name: 'birthday' }, { display: '地址', name: 'address', width: 400}],
                url: encodeURI('<%=Url.Action("GetUser","User")%>' + '/?conditions=' + conditions), sortName: 'userid',
                //data: { Rows: [{id:1,userName:2}],Total:12 },
                showTitle: false,
                //isScroll: false,
                dataAction: 'server',
                usePager: true,
                pageSize: 5,
                pageSizeOptions: [5, 10, 100,1000,10000,100000],
                //checkbox: true,
                fixedCellHeight: false,
                width: '100%', height: '100%',
                rownumbers: true
                //alternatingRow:true
            });

        }

    </script>
    <style type="text/css">
        body
        {
          overflow:hidden;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<%--<div id="searchbar" style="padding:10px;">
    <a class="l-button" style="width:60px; float:left; margin-left:10px;" onclick="f_add()">添加</a>

    <a class="l-button" style="width:60px; float:left; margin-left:10px;" onclick="f_modify()">修改</a>

    <a class="l-button" style="width:60px; float:left; margin-left:10px;" onclick="f_delete()">删除</a>

    <a class="l-button" style="width:60px; float:left; margin-left:10px;" onclick="f_reload()">刷新</a>

    <input type="text" style="float:left; margin-left:10px;" />
    <input type="button" class="l-button" style="float:left; margin-left:10px;" value="检索"/>
</div>--%>
<div id="toptoolbar"></div>

    <div class="l-panel-search">
        <input type="text" id="txtCondtions"  style="width:200px;"/>
        <input type="button" id="btnSearch" onclick="f_search()"  value="搜索" />
    </div>
    <div class="l-clear"></div>
    <div id="maingrid" style="margin: 0; padding: 0">
    </div>

</asp:Content>
